Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement new state caches #6176

Merged
merged 18 commits into from
Jan 4, 2024
Merged

feat: implement new state caches #6176

merged 18 commits into from
Jan 4, 2024

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Dec 11, 2023

Motivation

As part of n-historical states strategy, we want to keep bounded states in memory instead of unbounded states like what we have for now, see #6008

Description

  • Unify term for out state cache: BlockStateCache vs CheckpointStateCache
  • BlockStateCache interface has 2 implementations: StateContextCache and LRUBlockStateCache (new)
  • CheckpointStateCache has 2 implementations: CheckpointStateCache and PersistentCheckpointStateCache (new)
  • LRUBlockStateCache
    • Bounded by a max number of states, prune on add() to make its size consistent, oldest state is removed first
    • Head state always stay on top to make sure we always have it
  • PersistentCheckpointStateCache
    • Only states of the last n epochs are kept in memory, persist remaining states to db
    • Configured by maxEpochsInMemory
    • Given a block hex and its state, process that state to decide which checkpoint states are pruned based on its view

This PR only implements new state caches so it'll not affect production code, next PRs will consume them

part of #5968

Copy link

codecov bot commented Dec 11, 2023

Codecov Report

Merging #6176 (65bf923) into unstable (9262064) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files
@@            Coverage Diff            @@
##           unstable    #6176   +/-   ##
=========================================
  Coverage     80.31%   80.31%           
=========================================
  Files           202      202           
  Lines         19543    19543           
  Branches       1169     1169           
=========================================
  Hits          15695    15695           
  Misses         3820     3820           
  Partials         28       28           

Copy link
Contributor

github-actions bot commented Dec 11, 2023

Performance Report

✔️ no performance regression detected

🚀🚀 Significant benchmark improvement detected

Benchmark suite Current: 1ab20f0 Previous: 9262064 Ratio
Set add up to 64 items then delete first 1.7460 us/op 5.2636 us/op 0.33
Set add up to 128 items then delete last 3.7739 us/op 11.355 us/op 0.33
Set add up to 128 items then delete middle 3.7817 us/op 11.594 us/op 0.33
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 63.640 us/op 227.22 us/op 0.28
Full benchmark results
Benchmark suite Current: 1ab20f0 Previous: 9262064 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 723.49 us/op 882.71 us/op 0.82
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 52.171 us/op 149.53 us/op 0.35
BLS verify - blst-native 1.0475 ms/op 1.3454 ms/op 0.78
BLS verifyMultipleSignatures 3 - blst-native 2.2303 ms/op 2.8231 ms/op 0.79
BLS verifyMultipleSignatures 8 - blst-native 4.9461 ms/op 6.2146 ms/op 0.80
BLS verifyMultipleSignatures 32 - blst-native 18.146 ms/op 22.741 ms/op 0.80
BLS verifyMultipleSignatures 64 - blst-native 35.734 ms/op 44.776 ms/op 0.80
BLS verifyMultipleSignatures 128 - blst-native 70.928 ms/op 88.656 ms/op 0.80
BLS deserializing 10000 signatures 779.84 ms/op 961.65 ms/op 0.81
BLS deserializing 100000 signatures 8.0255 s/op 9.4560 s/op 0.85
BLS verifyMultipleSignatures - same message - 3 - blst-native 1.1552 ms/op 1.3400 ms/op 0.86
BLS verifyMultipleSignatures - same message - 8 - blst-native 1.2092 ms/op 1.5244 ms/op 0.79
BLS verifyMultipleSignatures - same message - 32 - blst-native 2.2758 ms/op 2.3705 ms/op 0.96
BLS verifyMultipleSignatures - same message - 64 - blst-native 3.0298 ms/op 3.5105 ms/op 0.86
BLS verifyMultipleSignatures - same message - 128 - blst-native 6.6268 ms/op 5.7658 ms/op 1.15
BLS aggregatePubkeys 32 - blst-native 22.027 us/op 26.778 us/op 0.82
BLS aggregatePubkeys 128 - blst-native 82.991 us/op 101.49 us/op 0.82
getAttestationsForBlock 28.660 ms/op 54.998 ms/op 0.52
getSlashingsAndExits - default max 96.186 us/op 161.13 us/op 0.60
getSlashingsAndExits - 2k 251.04 us/op 486.03 us/op 0.52
proposeBlockBody type=full, size=empty 3.7045 ms/op 6.3448 ms/op 0.58
isKnown best case - 1 super set check 337.00 ns/op 540.00 ns/op 0.62
isKnown normal case - 2 super set checks 329.00 ns/op 504.00 ns/op 0.65
isKnown worse case - 16 super set checks 329.00 ns/op 451.00 ns/op 0.73
CheckpointStateCache - add get delete 3.9580 us/op 6.3430 us/op 0.62
validate api signedAggregateAndProof - struct 2.3474 ms/op 2.8111 ms/op 0.84
validate gossip signedAggregateAndProof - struct 2.3198 ms/op 2.8176 ms/op 0.82
validate gossip attestation - vc 640000 1.1123 ms/op 1.4212 ms/op 0.78
batch validate gossip attestation - vc 640000 - chunk 32 134.49 us/op 197.46 us/op 0.68
batch validate gossip attestation - vc 640000 - chunk 64 119.60 us/op 168.42 us/op 0.71
batch validate gossip attestation - vc 640000 - chunk 128 113.78 us/op 164.02 us/op 0.69
batch validate gossip attestation - vc 640000 - chunk 256 113.13 us/op 149.08 us/op 0.76
pickEth1Vote - no votes 973.29 us/op 1.5348 ms/op 0.63
pickEth1Vote - max votes 10.296 ms/op 14.343 ms/op 0.72
pickEth1Vote - Eth1Data hashTreeRoot value x2048 17.085 ms/op 21.368 ms/op 0.80
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 27.607 ms/op 30.253 ms/op 0.91
pickEth1Vote - Eth1Data fastSerialize value x2048 481.88 us/op 681.19 us/op 0.71
pickEth1Vote - Eth1Data fastSerialize tree x2048 5.7153 ms/op 5.1212 ms/op 1.12
bytes32 toHexString 565.00 ns/op 578.00 ns/op 0.98
bytes32 Buffer.toString(hex) 338.00 ns/op 296.00 ns/op 1.14
bytes32 Buffer.toString(hex) from Uint8Array 511.00 ns/op 483.00 ns/op 1.06
bytes32 Buffer.toString(hex) + 0x 338.00 ns/op 313.00 ns/op 1.08
Object access 1 prop 0.24100 ns/op 0.18500 ns/op 1.30
Map access 1 prop 0.20800 ns/op 0.16800 ns/op 1.24
Object get x1000 4.9750 ns/op 8.6350 ns/op 0.58
Map get x1000 0.80600 ns/op 0.88300 ns/op 0.91
Object set x1000 28.171 ns/op 65.629 ns/op 0.43
Map set x1000 19.407 ns/op 48.444 ns/op 0.40
Return object 10000 times 0.22270 ns/op 0.26040 ns/op 0.86
Throw Error 10000 times 2.6792 us/op 4.0554 us/op 0.66
fastMsgIdFn sha256 / 200 bytes 1.9400 us/op 3.4970 us/op 0.55
fastMsgIdFn h32 xxhash / 200 bytes 323.00 ns/op 346.00 ns/op 0.93
fastMsgIdFn h64 xxhash / 200 bytes 377.00 ns/op 470.00 ns/op 0.80
fastMsgIdFn sha256 / 1000 bytes 6.1540 us/op 12.209 us/op 0.50
fastMsgIdFn h32 xxhash / 1000 bytes 458.00 ns/op 449.00 ns/op 1.02
fastMsgIdFn h64 xxhash / 1000 bytes 428.00 ns/op 459.00 ns/op 0.93
fastMsgIdFn sha256 / 10000 bytes 51.139 us/op 104.20 us/op 0.49
fastMsgIdFn h32 xxhash / 10000 bytes 1.7910 us/op 2.0180 us/op 0.89
fastMsgIdFn h64 xxhash / 10000 bytes 1.2320 us/op 1.4190 us/op 0.87
send data - 1000 256B messages 13.217 ms/op 21.000 ms/op 0.63
send data - 1000 512B messages 16.542 ms/op 29.037 ms/op 0.57
send data - 1000 1024B messages 23.896 ms/op 44.416 ms/op 0.54
send data - 1000 1200B messages 30.447 ms/op 46.676 ms/op 0.65
send data - 1000 2048B messages 34.733 ms/op 54.125 ms/op 0.64
send data - 1000 4096B messages 32.514 ms/op 51.022 ms/op 0.64
send data - 1000 16384B messages 95.748 ms/op 118.95 ms/op 0.80
send data - 1000 65536B messages 330.46 ms/op 547.98 ms/op 0.60
enrSubnets - fastDeserialize 64 bits 1.0450 us/op 1.6050 us/op 0.65
enrSubnets - ssz BitVector 64 bits 415.00 ns/op 558.00 ns/op 0.74
enrSubnets - fastDeserialize 4 bits 200.00 ns/op 243.00 ns/op 0.82
enrSubnets - ssz BitVector 4 bits 415.00 ns/op 586.00 ns/op 0.71
prioritizePeers score -10:0 att 32-0.1 sync 2-0 66.779 us/op 123.16 us/op 0.54
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 80.425 us/op 159.85 us/op 0.50
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 112.15 us/op 247.06 us/op 0.45
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 185.09 us/op 444.49 us/op 0.42
prioritizePeers score 0:0 att 64-1 sync 4-1 207.10 us/op 417.03 us/op 0.50
array of 16000 items push then shift 1.3003 us/op 1.9046 us/op 0.68
LinkedList of 16000 items push then shift 5.8790 ns/op 10.741 ns/op 0.55
array of 16000 items push then pop 103.90 ns/op 129.40 ns/op 0.80
LinkedList of 16000 items push then pop 5.9610 ns/op 11.343 ns/op 0.53
array of 24000 items push then shift 1.9094 us/op 2.7617 us/op 0.69
LinkedList of 24000 items push then shift 6.6870 ns/op 11.282 ns/op 0.59
array of 24000 items push then pop 114.64 ns/op 180.98 ns/op 0.63
LinkedList of 24000 items push then pop 6.6030 ns/op 9.2140 ns/op 0.72
intersect bitArray bitLen 8 4.9330 ns/op 6.8840 ns/op 0.72
intersect array and set length 8 50.862 ns/op 75.118 ns/op 0.68
intersect bitArray bitLen 128 27.865 ns/op 36.847 ns/op 0.76
intersect array and set length 128 684.21 ns/op 1.1540 us/op 0.59
bitArray.getTrueBitIndexes() bitLen 128 1.2000 us/op 1.9740 us/op 0.61
bitArray.getTrueBitIndexes() bitLen 248 1.9870 us/op 3.2610 us/op 0.61
bitArray.getTrueBitIndexes() bitLen 512 3.6900 us/op 6.5730 us/op 0.56
Buffer.concat 32 items 852.00 ns/op 1.1350 us/op 0.75
Uint8Array.set 32 items 1.5770 us/op 2.0590 us/op 0.77
Set add up to 64 items then delete first 1.7460 us/op 5.2636 us/op 0.33
OrderedSet add up to 64 items then delete first 2.6812 us/op 7.2579 us/op 0.37
Set add up to 64 items then delete last 1.9832 us/op 5.5425 us/op 0.36
OrderedSet add up to 64 items then delete last 2.9750 us/op 7.1603 us/op 0.42
Set add up to 64 items then delete middle 1.9905 us/op 5.9254 us/op 0.34
OrderedSet add up to 64 items then delete middle 4.3231 us/op 9.2349 us/op 0.47
Set add up to 128 items then delete first 3.9379 us/op 11.552 us/op 0.34
OrderedSet add up to 128 items then delete first 6.1637 us/op 16.282 us/op 0.38
Set add up to 128 items then delete last 3.7739 us/op 11.355 us/op 0.33
OrderedSet add up to 128 items then delete last 5.7094 us/op 16.011 us/op 0.36
Set add up to 128 items then delete middle 3.7817 us/op 11.594 us/op 0.33
OrderedSet add up to 128 items then delete middle 10.880 us/op 21.409 us/op 0.51
Set add up to 256 items then delete first 7.6283 us/op 22.884 us/op 0.33
OrderedSet add up to 256 items then delete first 12.142 us/op 33.132 us/op 0.37
Set add up to 256 items then delete last 7.4607 us/op 22.303 us/op 0.33
OrderedSet add up to 256 items then delete last 11.383 us/op 30.356 us/op 0.37
Set add up to 256 items then delete middle 7.4759 us/op 21.790 us/op 0.34
OrderedSet add up to 256 items then delete middle 30.521 us/op 52.723 us/op 0.58
transfer serialized Status (84 B) 1.4760 us/op 1.9290 us/op 0.77
copy serialized Status (84 B) 1.4850 us/op 1.7050 us/op 0.87
transfer serialized SignedVoluntaryExit (112 B) 1.4220 us/op 2.0280 us/op 0.70
copy serialized SignedVoluntaryExit (112 B) 1.1700 us/op 1.6550 us/op 0.71
transfer serialized ProposerSlashing (416 B) 1.5000 us/op 2.2130 us/op 0.68
copy serialized ProposerSlashing (416 B) 1.8540 us/op 2.2760 us/op 0.81
transfer serialized Attestation (485 B) 2.7070 us/op 2.3600 us/op 1.15
copy serialized Attestation (485 B) 2.9990 us/op 2.5650 us/op 1.17
transfer serialized AttesterSlashing (33232 B) 2.9940 us/op 2.3200 us/op 1.29
copy serialized AttesterSlashing (33232 B) 7.3650 us/op 9.4840 us/op 0.78
transfer serialized Small SignedBeaconBlock (128000 B) 3.1050 us/op 2.3830 us/op 1.30
copy serialized Small SignedBeaconBlock (128000 B) 15.849 us/op 31.971 us/op 0.50
transfer serialized Avg SignedBeaconBlock (200000 B) 2.3180 us/op 3.1790 us/op 0.73
copy serialized Avg SignedBeaconBlock (200000 B) 11.716 us/op 42.983 us/op 0.27
transfer serialized BlobsSidecar (524380 B) 2.3140 us/op 4.2070 us/op 0.55
copy serialized BlobsSidecar (524380 B) 85.090 us/op 146.24 us/op 0.58
transfer serialized Big SignedBeaconBlock (1000000 B) 2.4960 us/op 4.4800 us/op 0.56
copy serialized Big SignedBeaconBlock (1000000 B) 133.07 us/op 311.52 us/op 0.43
pass gossip attestations to forkchoice per slot 2.7513 ms/op 4.2049 ms/op 0.65
forkChoice updateHead vc 100000 bc 64 eq 0 456.47 us/op 840.39 us/op 0.54
forkChoice updateHead vc 600000 bc 64 eq 0 2.8829 ms/op 5.3986 ms/op 0.53
forkChoice updateHead vc 1000000 bc 64 eq 0 4.3581 ms/op 7.7944 ms/op 0.56
forkChoice updateHead vc 600000 bc 320 eq 0 2.6292 ms/op 4.4591 ms/op 0.59
forkChoice updateHead vc 600000 bc 1200 eq 0 2.7179 ms/op 4.6558 ms/op 0.58
forkChoice updateHead vc 600000 bc 7200 eq 0 3.3696 ms/op 5.5907 ms/op 0.60
forkChoice updateHead vc 600000 bc 64 eq 1000 10.013 ms/op 11.803 ms/op 0.85
forkChoice updateHead vc 600000 bc 64 eq 10000 9.7041 ms/op 12.833 ms/op 0.76
forkChoice updateHead vc 600000 bc 64 eq 300000 11.777 ms/op 20.630 ms/op 0.57
computeDeltas 500000 validators 300 proto nodes 3.1294 ms/op 7.0996 ms/op 0.44
computeDeltas 500000 validators 1200 proto nodes 2.9046 ms/op 8.0692 ms/op 0.36
computeDeltas 500000 validators 7200 proto nodes 2.8871 ms/op 7.1806 ms/op 0.40
computeDeltas 750000 validators 300 proto nodes 4.4180 ms/op 12.290 ms/op 0.36
computeDeltas 750000 validators 1200 proto nodes 4.4884 ms/op 10.497 ms/op 0.43
computeDeltas 750000 validators 7200 proto nodes 4.4280 ms/op 10.130 ms/op 0.44
computeDeltas 1400000 validators 300 proto nodes 8.9993 ms/op 19.360 ms/op 0.46
computeDeltas 1400000 validators 1200 proto nodes 8.6040 ms/op 19.653 ms/op 0.44
computeDeltas 1400000 validators 7200 proto nodes 8.6429 ms/op 18.852 ms/op 0.46
computeDeltas 2100000 validators 300 proto nodes 13.111 ms/op 28.083 ms/op 0.47
computeDeltas 2100000 validators 1200 proto nodes 13.474 ms/op 28.561 ms/op 0.47
computeDeltas 2100000 validators 7200 proto nodes 13.451 ms/op 28.396 ms/op 0.47
computeProposerBoostScoreFromBalances 500000 validators 3.2930 ms/op 3.7650 ms/op 0.87
computeProposerBoostScoreFromBalances 750000 validators 3.2858 ms/op 3.7182 ms/op 0.88
computeProposerBoostScoreFromBalances 1400000 validators 3.2785 ms/op 3.7535 ms/op 0.87
computeProposerBoostScoreFromBalances 2100000 validators 3.2841 ms/op 3.7797 ms/op 0.87
altair processAttestation - 250000 vs - 7PWei normalcase 1.5100 ms/op 2.1257 ms/op 0.71
altair processAttestation - 250000 vs - 7PWei worstcase 2.0971 ms/op 3.3369 ms/op 0.63
altair processAttestation - setStatus - 1/6 committees join 88.472 us/op 144.82 us/op 0.61
altair processAttestation - setStatus - 1/3 committees join 203.10 us/op 281.59 us/op 0.72
altair processAttestation - setStatus - 1/2 committees join 282.00 us/op 397.16 us/op 0.71
altair processAttestation - setStatus - 2/3 committees join 367.95 us/op 485.87 us/op 0.76
altair processAttestation - setStatus - 4/5 committees join 486.22 us/op 757.45 us/op 0.64
altair processAttestation - setStatus - 100% committees join 584.22 us/op 834.65 us/op 0.70
altair processBlock - 250000 vs - 7PWei normalcase 7.6621 ms/op 10.956 ms/op 0.70
altair processBlock - 250000 vs - 7PWei normalcase hashState 33.885 ms/op 45.221 ms/op 0.75
altair processBlock - 250000 vs - 7PWei worstcase 28.849 ms/op 46.567 ms/op 0.62
altair processBlock - 250000 vs - 7PWei worstcase hashState 89.836 ms/op 105.47 ms/op 0.85
phase0 processBlock - 250000 vs - 7PWei normalcase 2.1772 ms/op 3.2240 ms/op 0.68
phase0 processBlock - 250000 vs - 7PWei worstcase 26.103 ms/op 34.198 ms/op 0.76
altair processEth1Data - 250000 vs - 7PWei normalcase 296.00 us/op 742.25 us/op 0.40
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 11.004 us/op 15.749 us/op 0.70
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 40.483 us/op 51.783 us/op 0.78
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 14.351 us/op 22.794 us/op 0.63
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 10.811 us/op 16.387 us/op 0.66
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 63.640 us/op 227.22 us/op 0.28
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 1.0123 ms/op 1.3113 ms/op 0.77
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 1.7836 ms/op 1.9155 ms/op 0.93
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 1.4586 ms/op 1.9125 ms/op 0.76
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 2.2317 ms/op 4.0709 ms/op 0.55
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 1.4928 ms/op 2.5882 ms/op 0.58
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 3.8745 ms/op 5.8697 ms/op 0.66
Tree 40 250000 create 250.70 ms/op 379.43 ms/op 0.66
Tree 40 250000 get(125000) 99.040 ns/op 202.34 ns/op 0.49
Tree 40 250000 set(125000) 696.85 ns/op 1.1111 us/op 0.63
Tree 40 250000 toArray() 14.614 ms/op 31.983 ms/op 0.46
Tree 40 250000 iterate all - toArray() + loop 14.650 ms/op 34.035 ms/op 0.43
Tree 40 250000 iterate all - get(i) 39.928 ms/op 89.751 ms/op 0.44
MutableVector 250000 create 12.379 ms/op 16.386 ms/op 0.76
MutableVector 250000 get(125000) 5.3040 ns/op 7.2590 ns/op 0.73
MutableVector 250000 set(125000) 184.50 ns/op 322.25 ns/op 0.57
MutableVector 250000 toArray() 2.3355 ms/op 3.4435 ms/op 0.68
MutableVector 250000 iterate all - toArray() + loop 2.4389 ms/op 3.4827 ms/op 0.70
MutableVector 250000 iterate all - get(i) 1.3216 ms/op 1.5840 ms/op 0.83
Array 250000 create 2.2121 ms/op 3.5082 ms/op 0.63
Array 250000 clone - spread 1.0156 ms/op 1.3954 ms/op 0.73
Array 250000 get(125000) 0.94400 ns/op 1.0830 ns/op 0.87
Array 250000 set(125000) 1.1280 ns/op 4.9800 ns/op 0.23
Array 250000 iterate all - loop 143.40 us/op 187.86 us/op 0.76
effectiveBalanceIncrements clone Uint8Array 300000 17.232 us/op 56.013 us/op 0.31
effectiveBalanceIncrements clone MutableVector 300000 358.00 ns/op 418.00 ns/op 0.86
effectiveBalanceIncrements rw all Uint8Array 300000 171.72 us/op 201.83 us/op 0.85
effectiveBalanceIncrements rw all MutableVector 300000 62.459 ms/op 101.21 ms/op 0.62
phase0 afterProcessEpoch - 250000 vs - 7PWei 69.158 ms/op 116.75 ms/op 0.59
phase0 beforeProcessEpoch - 250000 vs - 7PWei 42.077 ms/op 40.528 ms/op 1.04
altair processEpoch - mainnet_e81889 375.74 ms/op 556.45 ms/op 0.68
mainnet_e81889 - altair beforeProcessEpoch 69.204 ms/op 91.079 ms/op 0.76
mainnet_e81889 - altair processJustificationAndFinalization 8.8890 us/op 22.896 us/op 0.39
mainnet_e81889 - altair processInactivityUpdates 3.9778 ms/op 6.6289 ms/op 0.60
mainnet_e81889 - altair processRewardsAndPenalties 48.627 ms/op 61.476 ms/op 0.79
mainnet_e81889 - altair processRegistryUpdates 2.2660 us/op 3.8570 us/op 0.59
mainnet_e81889 - altair processSlashings 572.00 ns/op 641.00 ns/op 0.89
mainnet_e81889 - altair processEth1DataReset 672.00 ns/op 682.00 ns/op 0.99
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.1196 ms/op 1.5945 ms/op 0.70
mainnet_e81889 - altair processSlashingsReset 2.8050 us/op 6.4540 us/op 0.43
mainnet_e81889 - altair processRandaoMixesReset 3.5490 us/op 6.8830 us/op 0.52
mainnet_e81889 - altair processHistoricalRootsUpdate 1.0090 us/op 839.00 ns/op 1.20
mainnet_e81889 - altair processParticipationFlagUpdates 1.5040 us/op 3.0300 us/op 0.50
mainnet_e81889 - altair processSyncCommitteeUpdates 598.00 ns/op 637.00 ns/op 0.94
mainnet_e81889 - altair afterProcessEpoch 77.827 ms/op 122.96 ms/op 0.63
capella processEpoch - mainnet_e217614 1.8368 s/op 2.2126 s/op 0.83
mainnet_e217614 - capella beforeProcessEpoch 440.17 ms/op 495.64 ms/op 0.89
mainnet_e217614 - capella processJustificationAndFinalization 10.859 us/op 21.954 us/op 0.49
mainnet_e217614 - capella processInactivityUpdates 20.211 ms/op 25.644 ms/op 0.79
mainnet_e217614 - capella processRewardsAndPenalties 368.35 ms/op 411.04 ms/op 0.90
mainnet_e217614 - capella processRegistryUpdates 6.8600 us/op 19.721 us/op 0.35
mainnet_e217614 - capella processSlashings 332.00 ns/op 590.00 ns/op 0.56
mainnet_e217614 - capella processEth1DataReset 296.00 ns/op 540.00 ns/op 0.55
mainnet_e217614 - capella processEffectiveBalanceUpdates 3.7917 ms/op 5.5959 ms/op 0.68
mainnet_e217614 - capella processSlashingsReset 1.3050 us/op 3.7090 us/op 0.35
mainnet_e217614 - capella processRandaoMixesReset 1.4440 us/op 4.3460 us/op 0.33
mainnet_e217614 - capella processHistoricalRootsUpdate 586.00 ns/op 532.00 ns/op 1.10
mainnet_e217614 - capella processParticipationFlagUpdates 1.3620 us/op 1.5360 us/op 0.89
mainnet_e217614 - capella afterProcessEpoch 195.72 ms/op 312.39 ms/op 0.63
phase0 processEpoch - mainnet_e58758 366.17 ms/op 423.82 ms/op 0.86
mainnet_e58758 - phase0 beforeProcessEpoch 118.62 ms/op 133.62 ms/op 0.89
mainnet_e58758 - phase0 processJustificationAndFinalization 10.399 us/op 17.355 us/op 0.60
mainnet_e58758 - phase0 processRewardsAndPenalties 54.904 ms/op 54.094 ms/op 1.01
mainnet_e58758 - phase0 processRegistryUpdates 6.4460 us/op 11.156 us/op 0.58
mainnet_e58758 - phase0 processSlashings 527.00 ns/op 592.00 ns/op 0.89
mainnet_e58758 - phase0 processEth1DataReset 507.00 ns/op 411.00 ns/op 1.23
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.3684 ms/op 1.1634 ms/op 1.18
mainnet_e58758 - phase0 processSlashingsReset 2.3450 us/op 3.0130 us/op 0.78
mainnet_e58758 - phase0 processRandaoMixesReset 2.4970 us/op 4.1640 us/op 0.60
mainnet_e58758 - phase0 processHistoricalRootsUpdate 371.00 ns/op 416.00 ns/op 0.89
mainnet_e58758 - phase0 processParticipationRecordUpdates 1.7180 us/op 3.6230 us/op 0.47
mainnet_e58758 - phase0 afterProcessEpoch 59.808 ms/op 96.221 ms/op 0.62
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.0086 ms/op 1.4032 ms/op 0.72
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.8582 ms/op 1.5249 ms/op 1.22
altair processInactivityUpdates - 250000 normalcase 25.149 ms/op 26.829 ms/op 0.94
altair processInactivityUpdates - 250000 worstcase 25.476 ms/op 29.982 ms/op 0.85
phase0 processRegistryUpdates - 250000 normalcase 3.1840 us/op 10.567 us/op 0.30
phase0 processRegistryUpdates - 250000 badcase_full_deposits 366.80 us/op 378.95 us/op 0.97
phase0 processRegistryUpdates - 250000 worstcase 0.5 114.05 ms/op 124.51 ms/op 0.92
altair processRewardsAndPenalties - 250000 normalcase 56.348 ms/op 56.703 ms/op 0.99
altair processRewardsAndPenalties - 250000 worstcase 59.404 ms/op 60.772 ms/op 0.98
phase0 getAttestationDeltas - 250000 normalcase 5.0653 ms/op 9.2207 ms/op 0.55
phase0 getAttestationDeltas - 250000 worstcase 5.1921 ms/op 9.2164 ms/op 0.56
phase0 processSlashings - 250000 worstcase 80.873 us/op 113.57 us/op 0.71
altair processSyncCommitteeUpdates - 250000 105.11 ms/op 162.17 ms/op 0.65
BeaconState.hashTreeRoot - No change 325.00 ns/op 255.00 ns/op 1.27
BeaconState.hashTreeRoot - 1 full validator 108.58 us/op 165.66 us/op 0.66
BeaconState.hashTreeRoot - 32 full validator 1.2000 ms/op 1.6256 ms/op 0.74
BeaconState.hashTreeRoot - 512 full validator 13.863 ms/op 17.786 ms/op 0.78
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 168.25 us/op 179.14 us/op 0.94
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 2.3594 ms/op 2.0429 ms/op 1.15
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 30.038 ms/op 25.428 ms/op 1.18
BeaconState.hashTreeRoot - 1 balances 134.91 us/op 122.26 us/op 1.10
BeaconState.hashTreeRoot - 32 balances 1.0585 ms/op 1.1313 ms/op 0.94
BeaconState.hashTreeRoot - 512 balances 11.355 ms/op 10.243 ms/op 1.11
BeaconState.hashTreeRoot - 250000 balances 208.61 ms/op 188.88 ms/op 1.10
aggregationBits - 2048 els - zipIndexesInBitList 10.884 us/op 17.872 us/op 0.61
byteArrayEquals 32 64.644 ns/op 75.469 ns/op 0.86
Buffer.compare 32 37.554 ns/op 55.987 ns/op 0.67
byteArrayEquals 1024 1.7810 us/op 2.0439 us/op 0.87
Buffer.compare 1024 43.638 ns/op 72.205 ns/op 0.60
byteArrayEquals 16384 28.138 us/op 32.549 us/op 0.86
Buffer.compare 16384 232.50 ns/op 233.59 ns/op 1.00
byteArrayEquals 123687377 188.45 ms/op 248.99 ms/op 0.76
Buffer.compare 123687377 4.7460 ms/op 7.0646 ms/op 0.67
byteArrayEquals 32 - diff last byte 63.148 ns/op 71.904 ns/op 0.88
Buffer.compare 32 - diff last byte 39.036 ns/op 56.804 ns/op 0.69
byteArrayEquals 1024 - diff last byte 1.7664 us/op 2.0405 us/op 0.87
Buffer.compare 1024 - diff last byte 46.508 ns/op 70.852 ns/op 0.66
byteArrayEquals 16384 - diff last byte 27.573 us/op 32.606 us/op 0.85
Buffer.compare 16384 - diff last byte 221.10 ns/op 273.00 ns/op 0.81
byteArrayEquals 123687377 - diff last byte 190.42 ms/op 257.49 ms/op 0.74
Buffer.compare 123687377 - diff last byte 5.6259 ms/op 8.1481 ms/op 0.69
byteArrayEquals 32 - random bytes 4.3970 ns/op 6.5270 ns/op 0.67
Buffer.compare 32 - random bytes 36.787 ns/op 67.899 ns/op 0.54
byteArrayEquals 1024 - random bytes 4.3330 ns/op 5.7570 ns/op 0.75
Buffer.compare 1024 - random bytes 35.374 ns/op 61.377 ns/op 0.58
byteArrayEquals 16384 - random bytes 4.3790 ns/op 6.3520 ns/op 0.69
Buffer.compare 16384 - random bytes 34.306 ns/op 61.439 ns/op 0.56
byteArrayEquals 123687377 - random bytes 7.5200 ns/op 9.1100 ns/op 0.83
Buffer.compare 123687377 - random bytes 37.170 ns/op 65.760 ns/op 0.57
regular array get 100000 times 38.944 us/op 46.174 us/op 0.84
wrappedArray get 100000 times 38.832 us/op 45.747 us/op 0.85
arrayWithProxy get 100000 times 9.6766 ms/op 15.150 ms/op 0.64
ssz.Root.equals 52.314 ns/op 55.321 ns/op 0.95
byteArrayEquals 51.045 ns/op 54.790 ns/op 0.93
Buffer.compare 8.7240 ns/op 11.567 ns/op 0.75
shuffle list - 16384 els 4.5670 ms/op 7.1310 ms/op 0.64
shuffle list - 250000 els 69.155 ms/op 105.18 ms/op 0.66
processSlot - 1 slots 19.011 us/op 19.253 us/op 0.99
processSlot - 32 slots 2.9135 ms/op 3.0217 ms/op 0.96
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 55.718 ms/op 56.795 ms/op 0.98
getCommitteeAssignments - req 1 vs - 250000 vc 2.2424 ms/op 2.7294 ms/op 0.82
getCommitteeAssignments - req 100 vs - 250000 vc 3.3697 ms/op 4.0091 ms/op 0.84
getCommitteeAssignments - req 1000 vs - 250000 vc 3.6228 ms/op 4.4669 ms/op 0.81
findModifiedValidators - 10000 modified validators 406.38 ms/op 700.01 ms/op 0.58
findModifiedValidators - 1000 modified validators 287.91 ms/op 497.08 ms/op 0.58
findModifiedValidators - 100 modified validators 297.91 ms/op 480.32 ms/op 0.62
findModifiedValidators - 10 modified validators 321.75 ms/op 465.75 ms/op 0.69
findModifiedValidators - 1 modified validators 289.64 ms/op 461.62 ms/op 0.63
findModifiedValidators - no difference 308.50 ms/op 440.49 ms/op 0.70
compare ViewDUs 3.8953 s/op 4.8560 s/op 0.80
compare each validator Uint8Array 1.5453 s/op 2.0666 s/op 0.75
compare ViewDU to Uint8Array 767.59 ms/op 1.4453 s/op 0.53
migrate state 1000000 validators, 24 modified, 0 new 711.50 ms/op 851.64 ms/op 0.84
migrate state 1000000 validators, 1700 modified, 1000 new 919.71 ms/op 1.1629 s/op 0.79
migrate state 1000000 validators, 3400 modified, 2000 new 1.1462 s/op 1.3371 s/op 0.86
migrate state 1500000 validators, 24 modified, 0 new 687.75 ms/op 807.20 ms/op 0.85
migrate state 1500000 validators, 1700 modified, 1000 new 953.35 ms/op 1.1087 s/op 0.86
migrate state 1500000 validators, 3400 modified, 2000 new 1.1966 s/op 1.4444 s/op 0.83
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.6700 ns/op 5.0600 ns/op 0.92
state getBlockRootAtSlot - 250000 vs - 7PWei 585.82 ns/op 587.79 ns/op 1.00
computeProposers - vc 250000 6.2484 ms/op 9.7256 ms/op 0.64
computeEpochShuffling - vc 250000 69.582 ms/op 108.34 ms/op 0.64
getNextSyncCommittee - vc 250000 108.74 ms/op 160.46 ms/op 0.68
computeSigningRoot for AttestationData 23.371 us/op 31.363 us/op 0.75
hash AttestationData serialized data then Buffer.toString(base64) 1.2577 us/op 2.4276 us/op 0.52
toHexString serialized data 846.44 ns/op 1.1199 us/op 0.76
Buffer.toString(base64) 155.31 ns/op 248.44 ns/op 0.63

by benchmarkbot/action

@twoeths twoeths marked this pull request as ready for review December 11, 2023 09:55
@twoeths twoeths requested a review from a team as a code owner December 11, 2023 09:55
Copy link
Contributor

@dapplion dapplion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did an initial pass, let's sync @tuyennhv for a deeper review

packages/beacon-node/src/metrics/metrics/lodestar.ts Outdated Show resolved Hide resolved
return state;
}
} catch (e) {
this.logger.debug("Error get or reload state", {epoch, rootHex}, e as Error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getOrReload already swallows all errors, I need to look more into the usage pattern of this but on a cursory look error handling should be more explicit than converting all errors to null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in regen.get*() apis, they only expect checkpoint state caches returning state or null. We could shift the error handling there but I think regen should also have to try/catch and try to load another checkpoint state. It depends on how we decide the api spec in not only this implementation but the generalized CheckpointStateCache interface and all of the implementations so that we have no issue switching the old CheckpointStateCache vs this new PersistentCheckpointStateCache

packages/beacon-node/src/chain/stateCache/types.ts Outdated Show resolved Hide resolved

// reload from disk or db based on closest checkpoint
this.logger.debug("Reload: read state", logMeta);
const newStateBytes = await this.persistentApis.read(persistedKey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it worth timing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes will also track it 👍

Copy link
Member

@wemeetagain wemeetagain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@twoeths twoeths merged commit b92ff14 into unstable Jan 4, 2024
14 of 15 checks passed
@twoeths twoeths deleted the tuyen/state_caches branch January 4, 2024 04:28
@wemeetagain
Copy link
Member

🎉 This PR is included in v1.14.0 🎉

ensi321 pushed a commit to ensi321/lodestar that referenced this pull request Jan 22, 2024
* feat: implement LRUBlockStateCache

* feat: implement PersistentCheckpointStateCache

* feat: implement findSeedStateToReload

* fix: add missing catch()

* fix: import path in state-transition

* fix: model CacheItem and type in PersistentCheckpointStateCache

* refactor: use for loop in PersistentCheckpointStateCache.processState

* chore: move test code to beforeAll() in persistentCheckpointsCache.test.ts

* feat: do not prune persisted state when reload

* fix: fifo instead of lru BlockStateCache

* fix: do not prune the last added item in FIFOBlockStateCache

* fix: sync epochIndex and cache in PersistentCheckpointStateCache

* chore: cleanup persistent checkpoint cache types

* chore: tweak comments

* chore: tweak more comments

* chore: reword persistent apis

* chore: add type to cpStateCache size metrics

* fix: metrics labels after rebasing from unstable

---------

Co-authored-by: Cayman <caymannava@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants